package com.arpa.wms.mapper;

import com.arpa.wms.domain.dto.ReceiveRegisterDTO;
import com.arpa.wms.domain.entity.ReceiveRegister;
import com.arpa.wms.domain.vo.ReceiveRegisterVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 收货登记 Mapper 接口
 * </p>
 *
 * @author LEO
 * @since 2020-08-04
 */
public interface ReceiveRegisterMapper extends BaseMapper<ReceiveRegister> {

    /**
     * 查询列表
     * @param receiveRegisterDTO
     * @return
     */
    List<ReceiveRegisterVO> queryList(ReceiveRegisterDTO receiveRegisterDTO);

    List<ReceiveRegisterVO> queryByInventoryStatus(@Param("list")List<String> list,@Param("groupCode")String groupCode );

    /**
     * 查询合计,包含总数
     * @param receiveRegisterDTO
     * @return
     */
    ReceiveRegisterVO queryListSum(ReceiveRegisterDTO receiveRegisterDTO);

    ReceiveRegisterVO getOneByCode(@Param("code")String code,@Param("groupCode") String groupCode);

    /**
     * 调整收货数量
     * @param receiveRegisterDTO
     * @return
     */
    int adjustReceiveQuantity(ReceiveRegisterDTO receiveRegisterDTO);

    /**
     * 更新收货登记的存货日期、批号
     * @param putawayCode
     * @return
     */
    @Update("update wms_receive_register wrr, wms_putaway_register wpr " +
            "set wrr.lot = wpr.lot, wrr.gmt_stock = wpr.gmt_stock " +
            "where wrr.code = wpr.receive_register_code and wpr.putaway_code = #{putawayCode} and wrr.group_code=#{groupCode}")
    int updateInventoryInfoByPutawayCode(@Param("putawayCode") String putawayCode,@Param("groupCode") String groupCode);

    /**
     * 统计上架明细单上架数量，更新指定收货确认单的上架数量
     * @param receiveRegisterCode
     */
    void refreshPutawayQuantity(@Param("code") String receiveRegisterCode,@Param("groupCode") String groupCode);

    /**
     * 统计上架明细单上架数量，更新指定收货确认单的上架和入库数量
     * @param receiveRegisterCode
     */
    void refreshPutawayAndInboundQuantity(@Param("code") String receiveRegisterCode, @Param("groupCode") String groupCode);
}
